{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8ba6e9e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pandas import Series,DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fe3c6261",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>吴军</td>\n",
       "      <td>男</td>\n",
       "      <td>75</td>\n",
       "      <td>87</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>王倩</td>\n",
       "      <td>女</td>\n",
       "      <td>34</td>\n",
       "      <td>93</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>张华</td>\n",
       "      <td>男</td>\n",
       "      <td>73</td>\n",
       "      <td>45</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>黄国华</td>\n",
       "      <td>男</td>\n",
       "      <td>87</td>\n",
       "      <td>96</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>马莉</td>\n",
       "      <td>女</td>\n",
       "      <td>96</td>\n",
       "      <td>55</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号   姓名 性别  语文  数学  英语\n",
       "0   1   吴军  男  75  87  76\n",
       "1   2   王倩  女  34  93  95\n",
       "2   3   张华  男  73  45  82\n",
       "3   4  黄国华  男  87  96  75\n",
       "4   5   马莉  女  96  55  89"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(\"ex1.csv\",encoding=\"gbk\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "45e13495",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>吴军</td>\n",
       "      <td>男</td>\n",
       "      <td>75</td>\n",
       "      <td>87</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>王倩</td>\n",
       "      <td>女</td>\n",
       "      <td>34</td>\n",
       "      <td>93</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>张华</td>\n",
       "      <td>男</td>\n",
       "      <td>73</td>\n",
       "      <td>45</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>黄国华</td>\n",
       "      <td>男</td>\n",
       "      <td>87</td>\n",
       "      <td>96</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>马莉</td>\n",
       "      <td>女</td>\n",
       "      <td>96</td>\n",
       "      <td>55</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   0    1  2   3   4   5\n",
       "0  1   吴军  男  75  87  76\n",
       "1  2   王倩  女  34  93  95\n",
       "2  3   张华  男  73  45  82\n",
       "3  4  黄国华  男  87  96  75\n",
       "4  5   马莉  女  96  55  89"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(\"ex1noheader.csv\",header=None,encoding=\"gbk\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1aaaadbc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>吴军</td>\n",
       "      <td>男</td>\n",
       "      <td>75</td>\n",
       "      <td>87</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>王倩</td>\n",
       "      <td>女</td>\n",
       "      <td>34</td>\n",
       "      <td>93</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>张华</td>\n",
       "      <td>男</td>\n",
       "      <td>73</td>\n",
       "      <td>45</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>黄国华</td>\n",
       "      <td>男</td>\n",
       "      <td>87</td>\n",
       "      <td>96</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>马莉</td>\n",
       "      <td>女</td>\n",
       "      <td>96</td>\n",
       "      <td>55</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号   姓名 性别  语文  数学  英语\n",
       "0   1   吴军  男  75  87  76\n",
       "1   2   王倩  女  34  93  95\n",
       "2   3   张华  男  73  45  82\n",
       "3   4  黄国华  男  87  96  75\n",
       "4   5   马莉  女  96  55  89"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(\"ex1noheader.csv\",header=None,encoding=\"gbk\",names=[\"学号\",\"姓名\",\"性别\",\"语文\",\"数学\",\"英语\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a25a7e17",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>学号</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>吴军</td>\n",
       "      <td>男</td>\n",
       "      <td>75</td>\n",
       "      <td>87</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>王倩</td>\n",
       "      <td>女</td>\n",
       "      <td>34</td>\n",
       "      <td>93</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>张华</td>\n",
       "      <td>男</td>\n",
       "      <td>73</td>\n",
       "      <td>45</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>黄国华</td>\n",
       "      <td>男</td>\n",
       "      <td>87</td>\n",
       "      <td>96</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>马莉</td>\n",
       "      <td>女</td>\n",
       "      <td>96</td>\n",
       "      <td>55</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名 性别  语文  数学  英语\n",
       "学号                    \n",
       "1    吴军  男  75  87  76\n",
       "2    王倩  女  34  93  95\n",
       "3    张华  男  73  45  82\n",
       "4   黄国华  男  87  96  75\n",
       "5    马莉  女  96  55  89"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(\"ex2.csv\",header=1,index_col=[\"学号\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fbc57677",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>学号</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>吴军</td>\n",
       "      <td>男</td>\n",
       "      <td>75</td>\n",
       "      <td>87</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>王倩</td>\n",
       "      <td>女</td>\n",
       "      <td>34</td>\n",
       "      <td>93</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>张华</td>\n",
       "      <td>男</td>\n",
       "      <td>73</td>\n",
       "      <td>45</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>黄国华</td>\n",
       "      <td>男</td>\n",
       "      <td>87</td>\n",
       "      <td>96</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>马莉</td>\n",
       "      <td>女</td>\n",
       "      <td>96</td>\n",
       "      <td>55</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     姓名 性别  语文  数学  英语\n",
       "学号                    \n",
       "1    吴军  男  75  87  76\n",
       "2    王倩  女  34  93  95\n",
       "3    张华  男  73  45  82\n",
       "4   黄国华  男  87  96  75\n",
       "5    马莉  女  96  55  89"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(\"ex3.csv\",skiprows=[0,2,3],index_col=[\"学号\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "693447fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>吴军</td>\n",
       "      <td>男</td>\n",
       "      <td>75.0</td>\n",
       "      <td>87</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>王倩</td>\n",
       "      <td>女</td>\n",
       "      <td>34.0</td>\n",
       "      <td>n</td>\n",
       "      <td>95.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>张华</td>\n",
       "      <td>男</td>\n",
       "      <td>NaN</td>\n",
       "      <td>45</td>\n",
       "      <td>82.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>黄国华</td>\n",
       "      <td>男</td>\n",
       "      <td>87.0</td>\n",
       "      <td>96</td>\n",
       "      <td>75.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>马莉</td>\n",
       "      <td>无</td>\n",
       "      <td>96.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>89.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号   姓名 性别    语文   数学    英语\n",
       "0   1   吴军  男  75.0   87   NaN\n",
       "1   2   王倩  女  34.0    n  95.0\n",
       "2   3   张华  男   NaN   45  82.0\n",
       "3   4  黄国华  男  87.0   96  75.0\n",
       "4   5   马莉  无  96.0  NaN  89.0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(\"ex4.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "60c3afbb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>吴军</td>\n",
       "      <td>男</td>\n",
       "      <td>75.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>王倩</td>\n",
       "      <td>女</td>\n",
       "      <td>34.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>95.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>张华</td>\n",
       "      <td>男</td>\n",
       "      <td>NaN</td>\n",
       "      <td>45.0</td>\n",
       "      <td>82.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>黄国华</td>\n",
       "      <td>男</td>\n",
       "      <td>87.0</td>\n",
       "      <td>96.0</td>\n",
       "      <td>75.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>马莉</td>\n",
       "      <td>NaN</td>\n",
       "      <td>96.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>89.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号   姓名   性别    语文    数学    英语\n",
       "0   1   吴军    男  75.0  87.0   NaN\n",
       "1   2   王倩    女  34.0   NaN  95.0\n",
       "2   3   张华    男   NaN  45.0  82.0\n",
       "3   4  黄国华    男  87.0  96.0  75.0\n",
       "4   5   马莉  NaN  96.0   NaN  89.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv(\"ex4.csv\",na_values={'n',\"无\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9182703d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>吴军</td>\n",
       "      <td>男</td>\n",
       "      <td>75</td>\n",
       "      <td>87</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>王倩</td>\n",
       "      <td>女</td>\n",
       "      <td>34</td>\n",
       "      <td>93</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>张华</td>\n",
       "      <td>男</td>\n",
       "      <td>73</td>\n",
       "      <td>45</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>黄国华</td>\n",
       "      <td>男</td>\n",
       "      <td>87</td>\n",
       "      <td>96</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>马莉</td>\n",
       "      <td>女</td>\n",
       "      <td>96</td>\n",
       "      <td>55</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号   姓名 性别  语文  数学  英语\n",
       "0   1   吴军  男  75  87  76\n",
       "1   2   王倩  女  34  93  95\n",
       "2   3   张华  男  73  45  82\n",
       "3   4  黄国华  男  87  96  75\n",
       "4   5   马莉  女  96  55  89"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_table(\"ex1.csv\",sep=\",\",encoding='gbk')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "dcdfba26",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1 吴军 男</td>\n",
       "      <td>75 87 76</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2 王倩 女</td>\n",
       "      <td>34 93 95</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3 张华 男</td>\n",
       "      <td>73 45 82</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4 黄国华 男 87 96 75</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5 马莉 女 96 55 89</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 学号        姓名  性别  语文  数学  英语\n",
       "0            1 吴军 男  75 87 76 NaN NaN NaN NaN\n",
       "1            2 王倩 女  34 93 95 NaN NaN NaN NaN\n",
       "2            3 张华 男  73 45 82 NaN NaN NaN NaN\n",
       "3  4 黄国华 男 87 96 75       NaN NaN NaN NaN NaN\n",
       "4   5 马莉 女 96 55 89       NaN NaN NaN NaN NaN"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_table(\"extxt.txt\",encoding='gbk')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "29645bdd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>吴军</td>\n",
       "      <td>男</td>\n",
       "      <td>75</td>\n",
       "      <td>87</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>王倩</td>\n",
       "      <td>女</td>\n",
       "      <td>34</td>\n",
       "      <td>93</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>张华</td>\n",
       "      <td>男</td>\n",
       "      <td>73</td>\n",
       "      <td>45</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>黄国华</td>\n",
       "      <td>男</td>\n",
       "      <td>87</td>\n",
       "      <td>96</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>马莉</td>\n",
       "      <td>女</td>\n",
       "      <td>96</td>\n",
       "      <td>55</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号   姓名 性别  语文  数学  英语\n",
       "0   1   吴军  男  75  87  76\n",
       "1   2   王倩  女  34  93  95\n",
       "2   3   张华  男  73  45  82\n",
       "3   4  黄国华  男  87  96  75\n",
       "4   5   马莉  女  96  55  89"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_table(\"extxt.txt\",sep='\\s+',encoding='gbk')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d38cbcc8",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_csv(\"ex4.csv\",index_col=[\"学号\"],na_values={'无','n'})\n",
    "data.to_csv(\"ex4out.csv\",encoding=\"gbk\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a70aa8e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_csv(\"ex4outnarep.csv\",encoding=\"gbk\",na_rep=\"null\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "84e78ee4",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_csv(\"ex4outnoindex.csv\",encoding=\"gbk\",index=False,header=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "d2439866",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6</td>\n",
       "      <td>方红</td>\n",
       "      <td>女</td>\n",
       "      <td>83</td>\n",
       "      <td>95</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>吕华</td>\n",
       "      <td>男</td>\n",
       "      <td>73</td>\n",
       "      <td>45</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8</td>\n",
       "      <td>陈宇</td>\n",
       "      <td>男</td>\n",
       "      <td>34</td>\n",
       "      <td>88</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9</td>\n",
       "      <td>张茜</td>\n",
       "      <td>女</td>\n",
       "      <td>89</td>\n",
       "      <td>91</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号  姓名 性别  语文  数学  英语\n",
       "0   6  方红  女  83  95  89\n",
       "1   7  吕华  男  73  45  82\n",
       "2   8  陈宇  男  34  88  86\n",
       "3   9  张茜  女  89  91  74"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_excel(\"data.xlsx\",sheet_name=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "bc8db9f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>语文</th>\n",
       "      <th>数学</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6</td>\n",
       "      <td>方红</td>\n",
       "      <td>女</td>\n",
       "      <td>83</td>\n",
       "      <td>95</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>吕华</td>\n",
       "      <td>男</td>\n",
       "      <td>73</td>\n",
       "      <td>45</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8</td>\n",
       "      <td>陈宇</td>\n",
       "      <td>男</td>\n",
       "      <td>34</td>\n",
       "      <td>88</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9</td>\n",
       "      <td>张茜</td>\n",
       "      <td>女</td>\n",
       "      <td>89</td>\n",
       "      <td>91</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号  姓名 性别  语文  数学  英语\n",
       "0   6  方红  女  83  95  89\n",
       "1   7  吕华  男  73  45  82\n",
       "2   8  陈宇  男  34  88  86\n",
       "3   9  张茜  女  89  91  74"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_excel(\"data.xlsx\",sheet_name=\"sheet2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "c9944f04",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'sheet1':    学号   姓名 性别  语文  数学  英语\n",
       " 0   1   吴军  男  75  87  76\n",
       " 1   2   王倩  女  34  93  95\n",
       " 2   3   张华  男  73  45  82\n",
       " 3   4  黄国华  男  87  96  75\n",
       " 4   5   马莉  女  96  55  89,\n",
       " 'sheet2':    学号  姓名 性别  语文  数学  英语\n",
       " 0   6  方红  女  83  95  89\n",
       " 1   7  吕华  男  73  45  82\n",
       " 2   8  陈宇  男  34  88  86\n",
       " 3   9  张茜  女  89  91  74}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_excel(\"data.xlsx\",sheet_name=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "731f85bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>学号</th>\n",
       "      <th>性别</th>\n",
       "      <th>英语</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>男</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>女</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>男</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>男</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>女</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   学号 性别  英语\n",
       "0   1  男  76\n",
       "1   2  女  95\n",
       "2   3  男  82\n",
       "3   4  男  75\n",
       "4   5  女  89"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_excel(\"data.xlsx\",sheet_name=0,usecols=[0,2,5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "2476cadf",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1=pd.read_excel(\"data.xlsx\",sheet_name=0)\n",
    "df2=pd.read_excel(\"data.xlsx\",sheet_name=1)\n",
    "df1.to_excel(\"twosheets.xlsx\",sheet_name=\"sheet1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "5e104fe5",
   "metadata": {},
   "outputs": [],
   "source": [
    "with pd.ExcelWriter('two.xlsx') as writer:\n",
    "    df1.to_excel(writer,sheet_name=\"sheet1\")\n",
    "    df2.to_excel(writer,sheet_name=\"sheet2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "925409ba",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
